package org.mymail.config;

import com.x8Peppers.test.targetNS.MailConfigDocument;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;
import org.apache.xmlbeans.XmlException;
import org.mymail.mail.MailConstants;

// Referenced classes of package org.mymail.config:
//            IProperties

public class SmtpMailProperties implements IProperties {

	public SmtpMailProperties() {
	}

	public Properties loadProperties() {
		HashMap propsValues = readPropertiesValues();
		String email = (String) propsValues.get("email");
		String host = (String) propsValues.get("host");
		String port = (String) propsValues.get("port");
		Properties props = new Properties();
		props.put("mail.smtp.user", email);
		props.put("mail.smtp.host", host);
		props.put("mail.smtp.port", port);
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.debug", "true");
		props.put("mail.smtp.socketFactory.port", port);
		props.put("mail.smtp.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");
		props.put("user.name", "Sharath.R");
		return props;
	}

	private HashMap<String, String> readPropertiesValues() {
		HashMap<String, String> propsValues = new HashMap<String, String>();
		try {
			MailConfigDocument configDoc = com.x8Peppers.test.targetNS.MailConfigDocument.Factory
					.parse(new File(MailConstants.configXMLLoc));
			com.x8Peppers.test.targetNS.MailConfigDocument.MailConfig config = configDoc
					.getMailConfig();
			propsValues.put("email", config.getEmail());
			propsValues.put("host", config.getHost());
			propsValues.put("port", config.getPort());
		} catch (XmlException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return propsValues;
	}
}